package com.tanhua.dubbo.api;

/**
 * @author maorf
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.QuestionMapper;
import com.tanhua.model.domain.db.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class QuestionApiImpl implements QuestionApi {

    @Autowired
    private QuestionMapper questionMapper;


    @Override
    public Question findQuestionByUserId(Long id) {
        return questionMapper.selectOne(new QueryWrapper<Question>().eq("user_id",id));
    }

    @Override
    public void save(Question question) {
        Question question1 = questionMapper.selectOne(new QueryWrapper<Question>().eq("user_id", question.getUserId()));
        if (question1==null){
            questionMapper.insert(question);
        }else{
            questionMapper.update(question,new QueryWrapper<Question>().eq("user_id", question.getUserId()));
        }
    }
}
